<template>
  <a-spin :spinning="loading" size="large">
    <div class="home-page">
      <div class="home-little" data-aos="flip-up">
        <a-avatar :size="50" :src="userInfo.avatar" v-if="!!userInfo && !!userInfo.avatar"></a-avatar>
        <a-avatar v-else :size="50">
          <template #icon><User-Outlined /></template>
        </a-avatar>
        <div>
          <span>
            {{ userInfo.realName || '未知人员' }}
          </span>
          <div>{{ userInfo.deptInfo?.[0].deptName }}</div> 
        </div>
        <a-button size="small" style="margin-top: 12px;margin-left: 20px;" @click="exitLogin">退出</a-button>
      </div> 
      <a-row :gutter="12">
        <a-col :span="8" v-for="(item, index) in dataList" :key="index" @click="goUrl(item.url)" data-aos="flip-down">
          <div class="home-item">
            <img :src="item.img" alt="">
            <span>{{ item.name }}</span>
          </div>          
        </a-col>
      </a-row>
    </div>
  </a-spin>
</template>

<script setup>
import { ref, inject, onMounted } from "vue"
import router from "@/route/index.js"
import { UserOutlined } from "@ant-design/icons-vue";

const loading = ref(false),
  toast = inject("toast"),
  userInfo = ref({}),
  dataList = ref([
    { name: "每日巡检", url: "/dayHome", icon: "todo-list-o", img: require("@/assets/images/icon/4.png") },
    { name: "能耗管理", url: "/energyHome", icon: "todo-list-o", img: require("@/assets/images/icon/2.png") },
    { name: "报修管理", url: "/repairHome", icon: "todo-list-o", img: require("@/assets/images/icon/5.png") },
    { name: "隐患随手拍", url: "/photoAdd", icon: "todo-list-o", img: require("@/assets/images/icon/iconP.png") },
    { name: "考试系统", url: "/test", icon: "todo-list-o", img: require("@/assets/images/icon/bj.png") }
  ]);

onMounted(() => {
  userInfo.value = JSON.parse(localStorage.getItem("SAVE_USER_INFO"));
})

function exitLogin() {
  localStorage.removeItem("SAVE_TOKEN")
  router.push("/?type=exit&corpId=" + localStorage.getItem("CORPID_VAL"))
}

function goUrl(url) {
  router.push(url)
}

</script>

<style lang="less" scoped>
:deep(.van-icon) {
  text-align: center;
}
.home-page {
  height: 100vh;
  background-color: rgb(243, 244, 249);
  padding: 15px 20px;

  .home-title {

      h1 {
        font-weight: 700;
        margin: 0;
      }

      span {
        color:rgb(181, 181, 181);
      }    

      img {
        width: 100%;
      }

  }

  .home-item {
    width: 100%;
    background-color: rgb(255, 255, 255);
    margin-top: 15px;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    line-height: 40px;

    span {
      display: block;
      font-size: 14px;
      font-weight: 700;
      text-align: center;
      white-space: nowrap;
      color: #222;
      font-family: Source Han Sans CN;
    }

    img {
      width: 50px;
      margin: 0 auto;
    }

  }

  .home-little {
    width: 100%;
    background-color: rgb(255, 255, 255);
    margin-top: 15px;
    border-radius: 8px;
    padding: 20px;
    display: flex;
    line-height: 40px;

    div > span {
      display: block;
      font-size: 16px;
      font-weight: 700;
      text-align: left;
      white-space: nowrap;
      margin-left: 25px;
      color: #343434;

      span {
        font-size: 12px;
      }

    }

    div {
      line-height: 1.5;

      div {
        margin-left: 25px;
        color: #717171;
      }

    }

  }
  .bottom-btn {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
  }
}
.reader-box {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.reader-box .desc {
  position: fixed;
  bottom: 140px;
  font-family: PingFang SC, PingFang SC;
  font-weight: bold;
  font-size: 15px;
  color: #ffffff;
  margin-top: 16px;
}
.reader-box .van-button {
  position: absolute;
  bottom: 70px;
  width: 90%;
  border: 1px solid #fff;
}
.home-little {
  width: 100%;
  background-color: rgb(235, 235, 235);
  margin-top: 15px;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  line-height: 40px;

  div > span {
    display: block;
    font-size: 16px;
    font-weight: 700;
    text-align: left;
    white-space: nowrap;
    margin-left: 25px;
    color: #343434;

    span {
      font-size: 12px;
    }

  }

  div {
    line-height: 1.5;

    div {
      margin-left: 25px;
      color: #717171;
    }

  }

}
</style>